package com.dyh.quickdemozwei.tmzljs;

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.CollectionUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Author: yhdong
 * @Date: 2021/11/8 10:39
 */
public class TmZlDsl {

    @Test
    public void test(){

        String str1 =
                "{\"title\":\"测试 成功发布的商品，请勿拍，拍下不发货，谢谢123456\",\"sell_points\":{\"sell_point_0\":\"测试适合所有人的商品测试用的不要乱动奥\"},\"short_title\":\"ddddd测试这是\",\"price\":\"1000000.29\",\"seller_cids\":[\"1603605815\",\"1603605811\",\"1603605817\",\"1603605816\"],\"sku\":[{\"sku_id\":\"4878877674136\",\"sku_price\":\"1000000.29\",\"sku_outerId\":\"s543423211\"},{\"sku_id\":\"4878877674137\",\"sku_price\":\"1000000.29\",\"sku_outerId\":\"s432322\"},{\"sku_id\":\"4878877674138\",\"sku_price\":\"1000000.29\",\"sku_outerId\":\"s43232232\"},{\"sku_id\":\"4878877674139\",\"sku_price\":\"1000000.29\",\"sku_outerId\":\"s342132\"}]}";

        Map<String,Object> jsMap1 = JSON.parseObject(str1,Map.class);
        Set<String> keySet1 = jsMap1.keySet();

        String str2 = "{\"title\":\"测试 成功发布的商品，请勿拍，拍下不发货，谢谢123456\",\"short_title\":\"ddddd测试这是\"}";
        Map<String,Object> jsMap2 = JSON.parseObject(str2,Map.class);
        Set<String> keySet2 = jsMap2.keySet();


        boolean b1 = judgeCanFast(keySet1);
        boolean b2 = judgeCanFast(keySet2);

        System.out.println();
    }

    public static boolean  judgeCanFast(Set<String> postKeys){
        for (String s : postKeys) {
            CanFastField  canFastField = id2CanFastFileds.get(s);
            if (canFastField==null)
                return false;
        }
        return true;
    }

    static Map<String,CanFastField> id2CanFastFileds = new HashMap<>();
    static {
        for (CanFastField canFastField : CanFastField.values()) {
            id2CanFastFileds.put(canFastField.name(),canFastField);
        }
    }


    public  enum CanFastField{
        title("标题"),
        subtitle("子标题"),
        show_title("展示标题"),
        short_title("无线短标题"),
        desc("pc描述"),
        wap_desc("无线描述"),
        wireless_desc("新版无线描述字段"),
        vertical_image("竖图"),
        white_bg_image("白底图"),
        large_screen_image("电子大屏图"),
        shop_category("店铺类目"),
        item_image("主图"),
        item_wireless_images("无线主图"),
        postage_id_increment("运费模板id"),
        image_video_type("主图视频比例类型"),
        main_video("主图视频"),
        three_to_four_images("3:4商品图片"),
        ;
        String description;
        CanFastField(String description){
            this.description = description;
        }

    }




}
